package com.Final.hj;

import android.app.Application;

import java.net.URISyntaxException;

import io.socket.client.IO;
import io.socket.client.Socket;
/*

    为啥这样呢，通过Intent也可以传递对象集合 可偏偏不能传递socket  因此只能通过Application传递
 */
public class ApplicationGetSocket extends Application{
    private Socket socket;

    @Override
    public void onCreate() {
        super.onCreate();
    }

    public void socketInit(final String myId, final String event) throws URISyntaxException {
        new Thread(new Runnable() {
            @Override
            public void run() {
                //与服务器建立连接
                try {
                    socket = IO.socket("http://192.168.43.124:8080");
                    socket.connect();
                    socket.emit(event, myId);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }

    public Socket getSocket() {
        return socket;
    }

    public void setSocket(Socket socket) {
        this.socket = socket;
    }
}
